local skel = fk.CreateSkill {
  name = "lb__zhuiqi",
  max_branches_use_time = function(self, player)
    local list = {}
    local room = Fk:currentRoom()
    for _, to in ipairs(room.players) do
      list[tostring(to.id)] = { [Player.HistoryRound] = 1 }
    end
    return list
  end
}

Fk:loadTranslationTable {
  ["lb__zhuiqi"] = "坠祈",
  --[":lb__zhuiqi"] = "当一名角色受到伤害后，你可以令其获得一名角色区域里的一张牌，若如此做，伤害来源可以弃置两张牌并令你受到1点无来源的雷电伤害。",
  --9.4
  --[":lb__zhuiqi"] = "每回合每名角色限一次，当一名角色受到伤害后，你可以令其获得一名角色区域里的一张牌，若如此做，伤害来源可以弃置两张牌并令你受到1点无来源的雷电伤害。",
  --10.2
  --[":lb__zhuiqi"] = "每回合每名角色限一次，当一名角色受到伤害后，你可以令其获得一名角色区域里的一张牌，若如此做，伤害来源可以弃置X张牌并令你受到1点无来源的雷电伤害（X为你的体力值）。",
  --10.5
  [":lb__zhuiqi"] = "每轮每名角色限一次，当一名角色受到伤害后，你可以令其获得一名角色区域里的一张牌，若如此做，伤害来源可以弃置两张牌并令你受到1点无来源的雷电伤害。",

  ["#lb__zhuiqi"] = "坠祈：你可以令%dest获得一名角色区域里的一张牌",
  ["#lb__zhuiqi-choose"] = "坠祈：你选择一名角色区域里的一张牌获得之",
  ["#lb__zhuiqi-obtain"] = "坠祈：获得 %dest 区域里的一张牌",
  ["#lb__zhuiqi-dis"] = "坠祈：你可以弃置两张牌并令 %dest 受到1点无来源的雷电伤害",
  --["#lb__zhuiqi-dis"] = "坠祈：你可以弃置 %arg张牌并令 %dest 受到1点无来源的雷电伤害",

  ["$lb__zhuiqi1"] = "尚不是止步的时候。",
  ["$lb__zhuiqi2"] = "纵使遍地荆棘，也当砥砺前行。",
}

skel:addEffect(fk.Damaged, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and not target.dead and
    skel:withinBranchTimesLimit(player, tostring(target.id), Player.HistoryRound)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local players = table.filter(room:getAlivePlayers(), function(p)
      return not p:isAllNude()
    end)
    event:setCostData(self, { tos = { target } })
    return #players > 0 and room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#lb__zhuiqi::" .. target.id,
    })
  end,
  on_use = function(self, event, target, player, data)
    player:addSkillBranchUseHistory(skel.name, tostring(target.id))
    local room = player.room
    local tos = table.filter(room:getAlivePlayers(), function(p)
      return not p:isAllNude()
    end)
    local ps = room:askToChoosePlayers(target, {
      targets = tos,
      min_num = 1,
      max_num = 1,
      skill_name = skel.name,
      prompt = "#lb__zhuiqi-choose",
      cancelable = false,
    })
    if #ps > 0 then
      local t = ps[1]
      local cid = room:askToChooseCard(target, {
        target = t,
        flag = "hej",
        skill_name = skel.name,
        prompt = "#lb__zhuiqi-obtain::" .. t.id,
      })
      room:obtainCard(target, cid, true, fk.ReasonPrey, target, skel.name)
      if data.from and #data.from:getCardIds("he") >= 2 --player.hp 
      and #room:askToDiscard(data.from, {
          --min_num = player.hp,
          --max_num = player.hp,
          min_num = 2,
          max_num = 2,
          include_equip = true,
          skill_name = skel.name,
          cancelable = true,
          prompt = "#lb__zhuiqi-dis::" .. player.id ,
          --prompt = "#lb__zhuiqi-dis::" .. player.id .. ":" .. player.hp,
        }) > 0 then
        room:damage {
          to = player,
          damage = 1,
          damageType = fk.ThunderDamage,
          skillName = skel.name,
        }
      end
    end
  end,
}, { check_skill_limit = true})

return skel